//
// Created by yu on 2023/9/24.
//
#pragma once
#include <vector>
#include <istream>
#include <iostream>
#include <serial/serial.h>

class CAN
{
 private:
 public:

  struct CANFrame
  {
    uint32_t id;
    uint8_t data[8];
  };

////  将ASCII编码字符串转为HEX
  static std::vector<unsigned char> CreateHexPack(const std::string &dataStr);
////  串口字符串解码转HEX字符串
  static std::string SerialDecode(const std::string &dataStr);
////  串口回复数据辨识数据帧
  static std::string extractFrame(const std::string &data);


////  CAN拓展帧id生成
  static uint32_t CreateCanExtendedId(uint8_t id, uint16_t torque, uint8_t mode);
////  生成CAN标准数据帧格式
  static std::vector<unsigned char> CreateCanStandardFrame(uint32_t id, const std::vector<std::string> &data);
////  生成CAN拓展数据帧格式
  static std::vector<unsigned char> CreateCanExtendedFrame(uint32_t id, const std::vector<std::string> &datas);
////  标准帧回复数据辨识
  static CANFrame ReadStandardFrame(const std::string &dataStr);
////  扩展帧回复数据辨识
  static CANFrame ReadExtendedFrame(const std::string &dataStr);
};

inline serial::Serial CANserialPort("/dev/can", 115200, serial::Timeout::simpleTimeout(100));

